package algorithm;

public class T00209 {
    public static void main(String[] args) {
        int[] nums = {2,3,1,2,4,3};
        int target = 7;
        System.out.println(new Solution().minSubArrayLen(target, nums));
    }

    static class Solution {
        public int minSubArrayLen(int target, int[] nums) {
            int left = 0, right = 0, len = Integer.MAX_VALUE;
            int sum = 0;
            while (right < nums.length) {
                sum += nums[right];
                right ++;
                while (sum >= target) {
                    if (right - left < len) {
                        len = right - left + 1;
                    }
                    sum -= nums[left];
                    left ++;
                }
            }
            return len == Integer.MAX_VALUE ? 0 : len;
        }
    }
}
